package com.woniu.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.commons.exception.YogaException;
import com.woniu.dao.YCoachResumeMapper;
import com.woniu.model.dto.CoachResumeDto;
import com.woniu.model.entity.YCoachResume;
import com.woniu.model.param.*;
import com.woniu.service.YCoachResumeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 胡歌
 * @since 2024年05月22日
 */
@Service
public class YCoachResumeServiceImpl extends ServiceImpl<YCoachResumeMapper, YCoachResume> implements YCoachResumeService {

    @Resource
    private YCoachResumeMapper coachResumeMapper;

    @Override
    public void addCoachResume(AddCoachResumeParam param) {
        QueryWrapper<YCoachResume> wrapper = new QueryWrapper<>();
        wrapper.eq("coach_id",param.getCoachId());
        YCoachResume resume = baseMapper.selectOne(wrapper);

        YCoachResume coachResume = BeanUtil.toBean(param, YCoachResume.class);
        resume.setImage(coachResume.getImage());
        resume.setCardImage(coachResume.getCardImage());
        resume.setHonor(coachResume.getHonor());
        resume.setJobResume(param.getJobResume());
        resume.setAge(param.getAge());
        resume.setAddress(param.getAddress());
        resume.setEducation(param.getEducation());
        resume.setGender(param.getGender());
        resume.setGraduate(param.getGraduate());
        coachResumeMapper.updateById(resume);
    }

    @Override
    public void updateImage(UpdateCoachImageParam param) {
        YCoachResume coachResume = coachResumeMapper.selectById(param.getCoachId());
        coachResume.setImage(param.getImage());
        coachResumeMapper.updateById(coachResume);
    }

    @Override
    public void updateCardImage(updateCardImageParam param) {
        YCoachResume coachResume = coachResumeMapper.selectById(param.getCoachId());
        coachResume.setCardImage(param.getCardImage());
        coachResumeMapper.updateById(coachResume);
    }

    @Override
    public void updateHonor(updateHonorParam param) {
        YCoachResume coachResume = coachResumeMapper.selectById(param.getCoachId());
        coachResume.setHonor(param.getHonor());
        coachResumeMapper.updateById(coachResume);
    }

    @Override
    public YCoachResume updateMessage(UpdateCoachMessageParam param) {
        YCoachResume coachResume = new YCoachResume();
        coachResume.setAddress(param.getAddress());
        coachResume.setAge(param.getAge());
        coachResume.setJobResume(param.getJobResume());
        coachResume.setPhone(param.getPhone());
        coachResume.setCoachId(param.getCoachId());
        coachResumeMapper.updateById(coachResume);
        return coachResume;
    }

    @Override
    public List<CoachResumeDto> coachResumeList() {
        List<CoachResumeDto> list=new ArrayList<>();
        QueryWrapper<YCoachResume> wrapper = new QueryWrapper<>();
        List<YCoachResume> hallInfos = coachResumeMapper.selectList(wrapper);
        for (YCoachResume info : hallInfos) {
            list.add(BeanUtil.toBean(info,CoachResumeDto.class));
        }
        return list;
    }

    @Override
    public YCoachResume yCoachResume(Integer coachId) {
        QueryWrapper<YCoachResume> wrapper = new QueryWrapper<>();
        wrapper.eq("coach_id",coachId);
        YCoachResume coachResume = coachResumeMapper.selectOne(wrapper);
        return coachResume;
    }

    /**
     * 根据token里面传的教练id查询自己的简历回去
     * @return
     */
    @Override
    public YCoachResume loadCoachResume(Integer coachId) throws YogaException {
        QueryWrapper<YCoachResume> wrapper = new QueryWrapper<>();
        System.out.println(coachId);
        wrapper.eq("coach_id",coachId);
        YCoachResume yCoachResume = baseMapper.selectOne(wrapper);



        return yCoachResume;
    }






}
